<?php
    require_once DB_PATH.'/DBConnection.php';
    
    class country{
        var $db;
        public function __construct(){
            
            $db=new DBConnection();
            $this->db=$db->getDbConnection();
        }
        
        public function createCountry($idCountry,$country,$idLanguage){
             $sql="insert into country (id_country, country, id_default_language) values ($idCountry, '$country',$idLanguage);";
             $stmt = $this->db->prepare($sql);
             $stmt->execute();
             return $idCountry;
        }    

        public function readCountry($idCountry){
             $sql="SELECT * from country where id_country=$idCountry";
                   
             $stmt = $this->db->prepare($sql);
             $stmt->execute();
             $result=$stmt->fetch(PDO::FETCH_ASSOC);
             return $result;
        }    

        public function updateCountry($idCountry, $country){
             $sql="update country set country='$country' where id_country=$idCountry";
                   
             $stmt = $this->db->prepare($sql);
             $stmt->execute();
             return $idCountry;
        }    

        public function deleteCountry($idCountry){
             $sql="delete from country where id_country=$idCountry";
                   
             $stmt = $this->db->prepare($sql);
             $stmt->execute();
             return $idCountry;
        }    
        
        public function listCountries($whereClause=''){
             $sql="SELECT * from country ".$whereClause;
                   
             $stmt = $this->db->prepare($sql);
             $stmt->execute();
             $result=$stmt->fetchAll(PDO::FETCH_ASSOC);
             return $result;
        }    
        
    }

?>